<!DOCTYPE html>
<html>
<head>
<title>添加内容</title>
#include("../include/common.html")
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>添加内容</h5>
            </div>
           <form id="inputForm" action="save" method="post">
           		<input type="hidden" name="categoryId" value="#(category.id)" />
	            <div class="ibox-content">
	                <div class="form-horizontal clearfix">
	                	<div class="form-group">
	                        <label class="col-sm-3 control-label">分类：</label>
	                        <div class="col-sm-3">
	                            #(category.name)
	                        </div>
	                    </div>
	                    <div class="form-group">
	                        <label class="col-sm-3 control-label">标题：</label>
	                        <div class="col-sm-3">
	                            <input class="form-control" type="text" name="title">
	                        </div>
	                    </div>
	                     <div class="form-group">
	                        <label class="col-sm-3 control-label">数据来源：</label>
	                        <div class="col-sm-3">
	                            <input class="form-control" type="text" name="source">
	                        </div>
	                    </div>
	                 <!--
	                    <div class="form-group">
	                        <label class="col-sm-3 control-label">图片：</label>
	                        <div class="col-sm-3">
	                            <input type="text" name="image" class="form-control" />
	                        </div>
	                        <div class="col-sm-3">
								<a href="javascript:;" id="filePicker" class="btn btn-primary">选择文件</a>
	                        </div>
	                    </div>  -->
	                    <div class="form-group">
                            <label class="col-sm-3 control-label">类型：</label>
                            <div class="col-sm-3">
                                <div class="radio">
                                    #for(selfTypeKey : selfTypes.keySet())
                                    <label class="m-r"><input name="type" value="#(selfTypeKey)" type="radio">#(selfTypes.get(selfTypeKey))</label>
                                    #end
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">发布时间：</label>
                            <div class="col-sm-3">
                                <input type="text" id="publishDate" name="publishDate" value="" class="form-control Wdate" onfocus="WdatePicker({dateFmt: 'yyyy-MM-dd HH:mm:ss'});" />
                                <script type="text/javascript">
                                function today(){
                                    var today=new Date();
                                    var h=today.getFullYear();
                                    var m=today.getMonth()+1;
                                    var d=today.getDate();
                                    var hh=today.getHours();
                                    var mm=today.getMinutes();
                                    var ss=today.getSeconds();
                                    m= m<10?"0"+m:m;     
                                    d= d<10?"0"+d:d;
                                    hh = hh < 10 ? "0" + hh:hh;
                                    mm = mm < 10 ? "0" +  mm:mm;
                                    ss = ss < 10 ? "0" + ss:ss;
                                    return h+"-"+m+"-"+d+" "+hh+":"+mm+":"+ss;
                                }
                                $("#publishDate").val(today());
                                </script>
                            </div>
                            <label class="col-sm-1 control-label">阅读数：</label>
                            <div class="col-sm-1">
                                <input class="form-control" type="text" name="hits" value="0">
                            </div>
                        </div>
	                    <div class="form-group">
	                        <label class="col-sm-3 control-label">关键词：</label>
	                        <div class="col-sm-3">
	                            <input class="form-control" type="text" name="keywords">
	                        </div>
	                    </div>
	                    <div class="form-group">
	                        <label class="col-sm-3 control-label">描述：</label>
	                        <div class="col-sm-3">
	                            <textarea class="form-control" style="height: 100px;" name="description"></textarea>
	                        </div>
	                    </div>
	                    <div class="form-group">
	                        <label class="col-sm-3 control-label">简介：</label>
	                        <div class="col-sm-8">
	                           <textarea id="introduction" name="introduction" class="ibox-content no-padding" style="height: 250px;"></textarea>
	                        </div>
	                    </div>
	                    #for(modelField : modelFields)
							#if(modelField.type=="input" && modelField.isEnabled)
								<div class="form-group">
									<label class="col-sm-3 control-label">#(modelField.alias)：</label>
									<div class="col-sm-3">
										<input type="text" name="#(modelField.name)" value="#(modelField.fieldAttribute.defaultValue)" class="form-control"/>
									    #if(modelField.prompt??)<span class="help-block m-b-none"><i class="fa fa-info-circle"></i>#(modelField.prompt)</span>#end
									</div>
								</div>
							#else if(modelField.type=="textarea" && modelField.isEnabled)
								<div class="form-group">
									<label class="col-sm-3 control-label">#(modelField.alias)：</label>
									<div class="col-sm-8">
										<textarea name="#(modelField.name)" class="form-control" style="height: 250px;">#(modelField.fieldAttribute.defaultValue)</textarea>
										#if(modelField.prompt??)<span class="help-block m-b-none"><i class="fa fa-info-circle"></i>#(modelField.prompt)</span>#end
									</div>
								</div>
							#else if(modelField.type=="editor" && modelField.isEnabled)
								<div class="form-group">
									<label class="col-sm-3 control-label">#(modelField.alias)：</label>
									<div class="col-sm-8">
										<textarea name="#(modelField.name)" class="ibox-content no-padding fieldEditor" style="height: 250px;">#(modelField.fieldAttribute.defaultValue)</textarea>
									    #if(modelField.prompt??)<span class="help-block m-b-none"><i class="fa fa-info-circle"></i>#(modelField.prompt)</span>#end
									</div>
								</div>
							#else if(modelField.type=="radio" && modelField.isEnabled)
								<div class="form-group">
									<label class="col-sm-3 control-label">#(modelField.alias)：</label>
									<div class="col-sm-3">
	                            		<div class="radio">
											#for(radioAttribute : modelField.fieldAttribute.radioAttributes)
												<label class="m-r"><input name="#(modelField.name)" value="#(radioAttribute[1])" type="radio" #if(modelField.fieldAttribute.defaultValue==radioAttribute[1]) checked #end>#(radioAttribute[0])</label>
											#end
										</div>
										#if(modelField.prompt??)<span class="help-block m-b-none"><i class="fa fa-info-circle"></i>#(modelField.prompt)</span>#end
									</div>
								</div>
							#else if(modelField.type=="checkbox" && modelField.isEnabled)
								<div class="form-group">
									<label class="col-sm-3 control-label">#(modelField.alias)：</label>
									<div class="col-sm-3">
										<div class="checkbox">
											#for(checkboxAttribute : modelField.fieldAttribute.checkboxAttributes) 
												<label class="m-r"><input name="#(modelField.name)" value="#(checkboxAttribute[1])" type="checkbox" #if(modelField.fieldAttribute.defaultValue==checkboxAttribute[1]) checked #end>#(checkboxAttribute[0])</label>
											#end
										</div>
										#if(modelField.prompt??)<span class="help-block m-b-none"><i class="fa fa-info-circle"></i>#(modelField.prompt)</span>#end
									</div>
								</div>
							#else if(modelField.type=="select" && modelField.isEnabled)
								<div class="form-group">
									<label class="col-sm-3 control-label">#(modelField.alias)：</label>
									<div class="col-sm-3">
										<select class="form-control" name="#(modelField.name)">
											#for(selectAttribute : modelField.fieldAttribute.selectAttributes)
												<option value="#(selectAttribute[1])" #if(modelField.fieldAttribute.defaultValue==selectAttribute[1]) checked #end>#(selectAttribute[0])</option>
											#end
										</select>
										#if(modelField.prompt??)<span class="help-block m-b-none"><i class="fa fa-info-circle"></i>#(modelField.prompt)</span>#end
									</div>
								</div>
							#else if(modelField.type=="date" && modelField.isEnabled)
								<div class="form-group">
									<label class="col-sm-3 control-label">#(modelField.alias)：</label>
									<div class="col-sm-3">
										<input type="text" name="#(modelField.name)" value="#(modelField.fieldAttribute.defaultValue)" class="form-control Wdate" onfocus="WdatePicker({dateFmt: '#(modelField.fieldAttribute.format)'});" />
									    #if(modelField.prompt??)<span class="help-block m-b-none"><i class="fa fa-info-circle"></i>#(modelField.prompt)</span>#end
									</div>
								</div>
							#else if(modelField.type=="file" && modelField.isEnabled)
								<div class="form-group">
									<label class="col-sm-3 control-label">#(modelField.alias)：</label>
									<div class="col-sm-3">
										<input type="text" name="#(modelField.name)" value="#(modelField.fieldAttribute.defaultValue)" class="form-control"/>
										#if(modelField.prompt??)<span class="help-block m-b-none"><i class="fa fa-info-circle"></i>#(modelField.prompt)</span>#end
									</div>
									<div class="col-sm-3">
										<a href="javascript:;" class="btn btn-primary fieldFilePicker">选择文件</a>
									</div>
								</div>
							#else if(modelField.type=="multipleFile" && modelField.isEnabled)
                                <div class="form-group" data-name="#(modelField.name)">
                                    <label class="col-sm-3 control-label">#(modelField.alias)：</label>
                                    <div class="col-sm-8">
                                        <a href="javascript:;" class="btn btn-primary fieldMultipleFilePicker">选择文件</a>
                                    </div>
                                    <div class="col-sm-3"></div>
                                    <div class="col-sm-8 multipleFile"></div>
                                </div>
							#end
						#end
	                </div>
	            </div>
               <div class="modal-footer col-sm-8 col-sm-offset-2">
                   <button type="button" class="btn btn-w-m btn-primary" onclick="save()">确定</button>
                   <button type="button" class="btn btn-w-m btn-default" onclick="history.back(); return false;">取消</button>
				   <button type="button" class="btn btn-w-m btn-primary" onclick="saveAndCommit()">确定并推送省局</button>
               </div>
            </form>
        </div>
    </div>
</body>
</html>
<script type="text/javascript">

$().ready(function() {

	var $inputForm = $("#inputForm");
	var $introduction = $("#introduction");
	var $filePicker = $("#filePicker");
	
	$filePicker.uploader();
	$introduction.editor();
	
	$.each($(".fieldEditor"),function(index,item){
		$(item).editor();
	});
	
	$.each($(".fieldFilePicker"),function(index,item){
		$(item).uploader();
	});
	
    $.each($(".fieldMultipleFilePicker"),function(index,item){
        $(item).uploader({multiple:true});
    });
    
    $(".multipleFile").on("click","a",function(){
    	$(this).parent().remove();
    });
	
	// 表单验证
	$inputForm.validate({
		rules: {
			source:"required",
			title: "required",
			categoryId: "required",
			type: "required",
			hits: "digits"
			#for(modelField : modelFields)
                #if(modelField.isEnabled && (modelField.isRequired || modelField.pattern??))
                	,#(modelField.name): {
                        #if(modelField.isRequired && modelField.pattern??)
                            required: true,
                            pattern: #(modelField.pattern)
                        #else if(modelField.isRequired)
                            required: true
                        #else if(modelField.pattern)
                            pattern: #(modelField.pattern)
                        #end
                    }
                #end
             #end
		},
		messages: {
			#set(modelFieldIndex=0)
			#for(modelField : modelFields)
				#if(modelField.isEnabled && modelField.pattern??)
					#if(modelFieldIndex>0),#end #(modelField.name): {
						pattern: "#(modelField.alias)错误"
					}
					#set(modelFieldIndex=modelFieldIndex+1)
				#end   
			#end
		}
	});

});

function save(){
    var targetForm=document.forms[0];
    targetForm.action="save";
    targetForm.method="post";
    targetForm.submit();
}

function saveAndCommit(){
    var targetForm=document.forms[0];
    targetForm.action="saveAndCommit";
    targetForm.method="post";
    targetForm.submit();
}
</script>
